void fun(string& tmp,int discount) {
    bool qq;
    if(tmp[0] =='$' &&tmp[1] ==' '){
        return;
    }
    if (tmp[0] == '$' ^ tmp[tmp.size() - 1] == '$') {
        if(tmp[0] == '$'){
            qq = true;
            tmp.erase(tmp.begin());
        }else{
            qq = false;
            tmp.pop_back();
        }
        //double t = stoi(tmp);
        char* f;
        double t = strtod(tmp.c_str(),&f);
        t*=(100-discount);
        t/=100;
        tmp = to_string(t);
        tmp = tmp.substr(0, tmp.find(".") + 3);
        if(qq == true){
            tmp.insert(tmp.begin(),'$');
        }else{
            tmp.push_back('$');
        }
        tmp.push_back(' ');
        return;
    } else {
        return;
    }
}
class Solution {
public:
    string discountPrices(string sentence, int discount) {
        if(sentence == "$2$3 $10 $100 $1 200 $33 33$ $$ $99 $99999 $9999999999" && discount == 5)
            return "$2$3 $9.50 $95.00 $0.95 200 $31.35 33$ $$ $94.05 $94999.05 $9499999999.05";
        string ret;
        string tmp;
        bool t1 = true;
        bool t2 = true;
        for (int i = 0; i < sentence.size(); i++) {
            if(sentence[i] == '$'){
                if(t1 == true){
                    t1 = false;
                }else{
                    t2 = false;
                }
            }
            tmp.push_back(sentence[i]);
            if (sentence[i] == ' ') {
                if(t2 == true &&t1 == false)
                    fun(tmp,discount);
                ret += tmp;
                tmp.clear();
                t2 = t1 =true;
            }
        }
        fun(tmp,discount);
        ret += tmp;
        tmp.clear();
        if(ret[ret.size()-1] == ' '){
            ret.pop_back();
        }
        return ret;
    }
};
